﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaiser.Modules.Hiner.Models.Product;
using Kaiser.Modules.Hiner.Repositories;
using Kaiser.Modules.Hiner.Models.Supplier;
using Kaiser.Modules.Hiner.Models.Supplier.SearchModels;
using Kaiser.Models;

namespace Kaiser.Repositories.iBatis.HINER
{
    public class SupplierRepositorie : ISupplierRepositorie
    {
        private IBatisHepler IBatisHepler = null;
        public SupplierRepositorie()
        {
            IBatisHepler = new BatisHepler("SQLMap.Hinner.config");
        }


        public DataGrid<SupplierOrder> SearchSupplier(SupplierSearch search, PagingInfo pageinfo)
        {
            var result = new DataGrid<SupplierOrder>();

            int totalCount = 0;

            result.TableResult = IBatisHepler.ExcuteSelect("SearchSupplier", search, pageinfo.Size, pageinfo.Index + 1, out totalCount);

            result.total = totalCount;

            return result;
        }

        public void Insert(SupplierBase model)
        {
            var result = IBatisHepler.ExcuteInsert("InsertSupplier", model);
        }

        public void Update(SupplierBase model)
        {
            var result = IBatisHepler.ExcuteUpdate("UpdateSupplier", model);
        }

        public int Delete(object primaryId)
        {
            var result = IBatisHepler.ExcuteDelete("DeleteSupplier", primaryId);
            return result;
        }

        public SupplierBase Get(object primaryId)
        {
            SupplierBase result = IBatisHepler.ExcuteSelectObj("GetSupplier", primaryId) as SupplierBase;
            //result.ProductList = IBatisHepler.ExcuteSelectObj("GetSupplier", primaryId) as IList<ProductBase>;
            //result.ProductList=new List<ProductBase>();
            //result.ProductList.Add(new ProductBase(){ProductName = "ProdcutTest1"});
            //result.ProductList.Add(new ProductBase() { ProductName = "ProdcutTest2" });
            //result.ProductList.Add(new ProductBase() { ProductName = "ProdcutTest3" });
            return result;
        }


        public int DeleteList(IList<string> ids)
        {
            throw new NotImplementedException();
        }
    }
}
